package com.heimachefu.module.user.dao;

import com.heimachefu.module.resource.entity.ResourceEntity;
import com.heimachefu.module.user.check.UserParam;
import com.heimachefu.module.user.entity.UserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<UserEntity,Long>,JpaSpecificationExecutor  {
    /**
     * 获取用户信息
     * @param username
     * @return
     */
    UserEntity findByUsername(String username);

    /**
     * 获取授权资源信息
     * @param userId
     * @return
     */
    @Query(value = "select r from ResourceEntity r  " +
            "left join RoleResourceEntity rr on rr.resourceId = r.resourceId left join UserRoleEntity ur on ur.roleId = rr.roleId" +
            " where ur.userId = ?1 and r.resourceLevel = 1")
    List<ResourceEntity> getAuthResourceForUser(Long userId);

    /**
     * 获取用户分页参数
     * @return
     */


    /**
     * 获取用户分页参数
     * @param pageable
     * @return
     *//*
    Page<UserEntity> findAll(Pageable pageable);*/
}
